#ifndef _DS_SQ_STACK_H
#define _DS_SQ_STACK_H

#include "../ds_types.h"
#include <stdlib.h>
#include <string.h>

#define STACK_INIT_SIZE 20
#define STACK_INCREMENT 10

extern Status sqstack_init(sq_stack *s, size_t struct_size);

static inline Status sqstack_destroy(sq_stack *s)
{
	free(s->base);
	s->stacksize = 0;
}

static inline Status sqstack_clear(sq_stack *s)
{
	s->top = s->base;
}

static inline Bool sqstack_empty(const sq_stack *s)
{
	return s->top == s->base;
}

static inline size_t sqstack_length(const sq_stack *s, size_t struct_size)
{
	return (s->top - s->base) / struct_size;
}

static inline Status sqstack_gettop(const sq_stack *s,void *e, size_t struct_size)
{
	if(sqstack_empty(s)) return ERROR;
	memcpy(e, s->top - struct_size, struct_size);
}

extern Status push(sq_stack *s, const void *e, size_t struct_size);

extern Status pop(sq_stack *s, void *e, size_t struct_size);

extern Status sqstack_traverse(const sq_stack *s, Bool visit(const void*), size_t struct_size);
#endif
